#ifndef __APP_BUFFER_H__
#define __APP_BUFFER_H__

#include "pthread.h"
#include "app_common.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "log/log.h"




typedef struct
{
    char *buf_ptr;
    int buf_size;
    int data_len;

} SubBuffer;

typedef struct
{
    SubBuffer *sub_buf[2]; /* 指针数组，指向两个 SubBuffer 类型的空间，  一读一写，注意是动态切换的*/
    int r_index;             /* 读下标*/
    int w_index;             /* 写下标*/
    pthread_mutex_t r_mutex; /* 解决读线程竞争冲突 */
    pthread_mutex_t w_mutex; /* 解决写线程竞争冲突 */

} Buffer;

Buffer *app_buffer_init(int size);

returnType_t app_buffer_write(Buffer *buffer, char *data, int data_len);

int app_buffer_read(Buffer *buffer, char *buf, int buf_len);

returnType_t app_buffer_free(Buffer *buffer);

#endif /* __APP_BUFFER_H__ */